#include "app_eeprom.h"
#include <string.h>
#include "bsp_e2prom.h"
#include "app_sub_can.h"


EEP_t eep;

void app_eep_state_init(void)
{
    memset(&eep,0,sizeof(EEP_t));

    for (uint8_t i = 0; i < 100; i++)
    {
        eep.wBuf[i] = i;
    }

}

void app_eep_run(void)
{
    static uint8_t step = 0;
     switch (step)
     {
        case 0:
        if(eep.test_w_en == true)
        {
            eep.test_w_en = false;
            app_eep_state_init();
            if(dv_E2PROM.fWriteU8Data(0,eep.wBuf,100))
            {
                subCan.txMes1.mes.wSTeep = 1;
            }
            else
            {
                subCan.txMes1.mes.wSTeep = 0;
            }
        }
        if(eep.test_r_en == true)
        {
            eep.test_r_en = false;
            app_eep_state_init();
            dv_E2PROM.fReadU8Data(0,eep.rBuf,100);
            subCan.txMes1.mes.rSTeep = 1;
            for (uint8_t i = 0; i < 100; i++)
            {
                if(eep.wBuf[i]!= eep.rBuf[i])
                {
                    subCan.txMes1.mes.rSTeep = 0;
                    break;
                }
            }
        }
        break;        
        default:
        break;
     }
}